﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using ProjetoBe.cs;
using ProjetoUtil;

namespace ProjetoDalc.cs
{
    public class RelatorioFinanceiroDalc
    {

        public decimal SelecionarValorTotalData(DateTime data)
        {
            SqlDataReader reader;
            List<string> valores = new List<string>();
            using (SqlConnection conexao = Connection.CriarConexao())
            {
                SqlCommand command = new SqlCommand();
                SqlDataAdapter adapter = new SqlDataAdapter();

                command.Connection = conexao;
                command.CommandText = "SELECT INGRESSO_VALOR FROM INGRESSO WHERE INGRESSO_DATA = @data";
                command.Parameters.AddWithValue("@data", data);


                conexao.Open();
                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        valores.Add((reader.GetString(0)));
                    }
                }
                conexao.Close();
                decimal total = 0;

                foreach (string i in valores)
                    total = total + Convert.ToDecimal(i);

                return total;
            }
        }

        public decimal SelecionarDescontoTotal(DateTime data)
        {

            SqlDataReader reader;
            List<string> desconto = new List<string>();
            using (SqlConnection conexao = Connection.CriarConexao())
            {
                SqlCommand command = new SqlCommand();
                SqlDataAdapter adapter = new SqlDataAdapter();

                command.Connection = conexao;
                command.CommandText = "SELECT INGRESSO_DESCONTO FROM INGRESSO WHERE INGRESSO_DATA = @data";
                command.Parameters.AddWithValue("@data", data);

                conexao.Open();
                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        desconto.Add((reader.GetString(0)));
                    }
                }
                conexao.Close();
                decimal totaldesconto = 0;

                foreach (string i in desconto)
                    totaldesconto = totaldesconto + Convert.ToDecimal(i);

                return totaldesconto;
            }
        }

        public int SelecionarNumeroIngresso(DateTime data)
        {
            using (SqlConnection conexao = Connection.CriarConexao())
            {
                SqlCommand command = new SqlCommand();
                SqlDataAdapter adapter = new SqlDataAdapter();

                command.Connection = conexao;
                command.CommandText = "SELECT COUNT (INGRESSO_ID)FROM INGRESSO WHERE INGRESSO_DATA = @data";
                command.Parameters.AddWithValue("@data", data);

                conexao.Open();
                int ingresso = (int)command.ExecuteScalar();
                conexao.Close();

                return ingresso;
            }
        }
    }
}
